home *** CD-ROM | disk | FTP | other *** search
/ Plug-In Power Pack for Netscape Communicator / Plug-In Power Pack for Netscape Communicator.iso / plugins / dataviews / dvtools / examples / programs / axis.c next >
Encoding:
C/C++ Source or Header  |  1997-05-08  |  7.8 KB  |  292 lines

  1. #ifndef lint
  2. static char SccsId[]= "@(#)axis.c    V1.15    3/13/95";
  3. #endif
  4. /*
  5. |    file -- axis.c
  6. |====================================================================
  7. |
  8. |    This program exercises the VUax* routines by drawing axes in a
  9. |    variety of orientations.  It sleeps between views and then
  10. |    quits.
  11. |
  12. |    This program expects the name of a display device.
  13. |
  14. |=====================================================================
  15. */
  16. #include <windows.h>
  17. /*
  18.  *  DV-Tools header files
  19.  */
  20. #include "std.h"        /* <stdio.h> etc, scalar & macro definitions */
  21. #include "dvstd.h"        /* public types & constants */
  22. #include "dvtools.h"        /* constants used by T routines */
  23. #include "dvaxis.h"        /* constants used by VUax routines */
  24. #include "dvtypes.h"        /* other types for axis and tick routines */
  25. #include "dvGR.h"        /* constants used by window mgt & GR routines */
  26. #include "VOstd.h"        /* constants used by VO & VOob routines */
  27. #include "Tfundecl.h"        /* T routines (screens, drawports & views) */
  28. #include "GRfundecl.h"        /* GR routines (interface to display device) */
  29. #include "VUfundecl.h"        /* VU routines (utility) */
  30.  
  31.  
  32. /* Constants */
  33. #define  DVPATH            (char *)NULL
  34. #define  DISPFORMS_STB     (char *)NULL
  35. #define  DVDEVICE          (char *)NULL
  36. #define  DVCOLORTABLE      (char *)NULL
  37. #define  VIEW_NAME       "axis.v"
  38. #define  SCREEN_VIEWPORT   (RECTANGLE *)NULL
  39. #define  DRAWING_VIEWPORT  (RECTANGLE *)NULL
  40.  
  41.  
  42. /* Global forward function declarations */
  43.  
  44. /* Local forward function declarations */
  45. LOCAL void LabelFunction V_P_ ((int *argp, double *valuep,
  46.                                 ADDRESS labelp, TIC_DATA *tdp));
  47.  
  48.  
  49. /*
  50.  *   MAIN PROGRAM
  51.  */
  52. int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
  53.                      LPSTR lpCmdLine,  int nCmdShow  )
  54. {
  55.   /*
  56.    *  program arguments
  57.    *    argv[1] - display device (default is DVDEVICE)
  58.    */
  59.  
  60.   /* Define & initialize device name */
  61.   char *device_name = DVDEVICE;    /* default device name */
  62.  
  63.   /* Define display variables */
  64.   OBJECT screen;        /* display device, the window */
  65.  
  66.   int i, j,            /* loop counters */
  67.       direction = 1,        /* direction of the axis */
  68.       Textsize,            /* size of text used */
  69.       Labelside,        /* side to display labels */
  70.       Tickside;            /* side to display tick marks */
  71.   DV_POINT start,        /* starting point of axis */
  72.            end;            /* ending point of axis */
  73.   AXISDESC axis;        /* axis data structure */
  74.   int argc = 0;
  75.   char **argv;
  76.  
  77.  
  78.   make_argv(&argc,&argv,GetCommandLine());
  79.  
  80.   /*-----------------
  81.    *   Initialization
  82.    *
  83.    *   TInit:    perform the initialization of DV-Tools
  84.    *             TInit reads your configuration file and any
  85.    *             environment variables or logical names set.
  86.    */
  87.   TInit (DVPATH, DISPFORMS_STB);
  88.  
  89.   /*
  90.    *   TscOpenSet:  opens a device as a screen object using
  91.    *                specified attributes
  92.    *   TscErase:    Erase the entire screen in the default
  93.    *                background color
  94.    */
  95.   if (argc > 1)
  96.     device_name = argv[1];
  97.   screen = TscOpenSet (device_name, DVCOLORTABLE,
  98.                V_WINDOW_NAME, "axis.c",
  99.                V_X_EXPOSURE_BLOCK, YES, V_END_OF_LIST);
  100.   if (!screen)
  101.     {
  102.       printf ("Must specify device on command line or");
  103.       printf (" in DataViews configuration file.\n");
  104.       S_EXIT (EXIT_ERR);
  105.     }
  106.   TscErase( screen );
  107.   Sleep( 1000 );
  108.  
  109.   /* Loop through 16 axis orientation/layout combinations */
  110.   for (i = 1; i <= 16; i++)
  111.     {
  112.  
  113.       Textsize = 1 + (i & 1);
  114.  
  115.       /* Define the axis direction */
  116.       switch (i % 4)
  117.     {
  118.     case AXIS_RIGHT:
  119.       direction = AXIS_RIGHT;
  120.       break;
  121.  
  122.     case AXIS_UP:
  123.       direction = AXIS_UP;
  124.       break;
  125.  
  126.     case AXIS_LEFT:
  127.       direction = AXIS_LEFT;
  128.       break;
  129.  
  130.     default:
  131.       direction = AXIS_DOWN;
  132.       break;
  133.     }
  134.  
  135.       /*
  136.        * Define the side of axis which the ticks will be placed
  137.        * Default is left for axis up; right for axis right.
  138.        */
  139.       if (i & 4)
  140.     Tickside = LEFT_SIDE;
  141.       else
  142.     Tickside = RIGHT_SIDE;
  143.  
  144.       /*
  145.        *   VUaxCreate:  Creates and returns an axis descriptor
  146.        *               Start and end value are passed.
  147.        */
  148.       axis = (AXISDESC) VUaxCreate ((double) 0, (double) 10);
  149.  
  150.       switch (direction)
  151.     {
  152.     case AXIS_RIGHT:
  153.       start.x = 50;
  154.       start.y = 100;
  155.       end.x = 350;
  156.       end.y = 100;
  157.       Labelside = RIGHT_SIDE;
  158.       break;
  159.  
  160.     case AXIS_LEFT:
  161.       start.x = 350;
  162.       start.y = 100;
  163.       end.x = 50;
  164.       end.y = 100;
  165.       Labelside = LEFT_SIDE;
  166.       break;
  167.  
  168.     case AXIS_UP:
  169.       start.x = 100;
  170.       start.y = 50;
  171.       end.x = 100;
  172.       end.y = 350;
  173.       Labelside = LEFT_SIDE;
  174.       break;
  175.  
  176.     case AXIS_DOWN:
  177.       start.x = 100;
  178.       start.y = 350;
  179.       end.x = 100;
  180.       end.y = 50;
  181.       Labelside = RIGHT_SIDE;
  182.       break;
  183.     }
  184.  
  185.       /*
  186.        *   VUaxSet:  Set axis descriptor attribute fields
  187.        */
  188.       VUaxSet (axis,
  189.            AXIS_DIRECTION, direction,
  190.            AXIS_LENGTH, (int)300,
  191.            AXIS_START_POINT, &start,
  192.            DRAW_GRID, (int)YES,
  193.            GRID_LENGTH, (int)300,
  194.            GRID_LINE_TYPE, (int)2,
  195.            LABEL_FUNCTION, LabelFunction, (ADDRESS) NULL,
  196.            LABEL_TEXTSIZE, Textsize,
  197.            LABEL_SIDE, Labelside,
  198.            TICK_SIDE, Tickside,
  199.            V_END_OF_LIST);
  200.  
  201.       /*
  202.        *   GRmove_and_vector:  Draws a vector between two points
  203.        */
  204.       GRmove_and_vector (&start, &end);
  205.  
  206.       /* Draw the axis incrementally, a section at a time */
  207.       /* (VUaxDraw would draw the whole axis at once.) */
  208.       for (j = 0; j < 10; j++)
  209.     {
  210.       /*
  211.            *   VUaxSet:  Sets axis descriptor attribute fields.
  212.            *             AXIS_NEW_START_VALUE - New start value of axis.
  213.            */
  214.       if (j == 5)
  215.         VUaxSet (axis, AXIS_NEW_START_VALUE, 10.0, V_END_OF_LIST);
  216.  
  217.       /*
  218.            *   VUaxDrawRange:  Draws a portion of the axis, which
  219.            *                   is determined by the given start
  220.            *               and end value.
  221.            */
  222.       if (j == 4 || j == 9)
  223.         VUaxDrawRange (axis, (double) j * 2, (double) (j * 2 + 2));
  224.       else
  225.         VUaxDrawRange (axis, (double) j * 2, (double) (j * 2 + 2));
  226.     }
  227.  
  228.       /*
  229.        *   VUaxDestroy:  Destroys an axis descriptor, freeing its memory
  230.        *   GRflush:      Flushes display buffers
  231.        *   TscErase:     Erase the entire screen in the default
  232.        *                 background color
  233.        */
  234.       VUaxDestroy (axis);
  235.       GRflush ();
  236.       Sleep (2000);
  237.       TscErase (screen);
  238.     }
  239.  
  240.   /*--------------------
  241.    *   Termination
  242.    *
  243.    *   TscErase:    Erase the entire screen in the default
  244.    *                background color
  245.    *   TscClose:    Close the current display screen
  246.    *   TTerminate:  Perform the clean-up for DV-Tools
  247.    */
  248.   TscErase (screen);
  249.   TscClose (screen);
  250.   TTerminate ();
  251.   return EXIT_OK;
  252. }
  253.  
  254. /*-------------------------------------------------------------*/
  255. /* This function formats the tick value into a suitable string */
  256. /*ARGSUSED*/
  257. LOCAL void
  258. LabelFunction (argp, valuep, labelp, tdp)
  259.      int *argp;
  260.      double *valuep;
  261.      ADDRESS labelp;
  262.      TIC_DATA *tdp;
  263. {
  264.   union
  265.     {
  266.       ADDRESS alias;
  267.       LABEL_SIZE *size;
  268.       char *label;
  269.     } label_info;
  270.   
  271.   label_info.alias = labelp;
  272.  
  273.   /*
  274.    * when valuep is NULL, labelp is a LABEL_SIZE * parameter,
  275.    * and will receive information about the tick labels;
  276.    * when valuep is non-NULL, labelp is a char* parameter, and
  277.    * will receive the label corresponding to the valuep value. 
  278.    */
  279.   if (valuep == NULL)
  280.     {
  281.       /* Return a size report, indicating how big a label will be */
  282.       label_info.size->StringLength = 13;
  283.       label_info.size->NumLines = 2;
  284.       label_info.size->LongestLine = 6;
  285.     }
  286.   else
  287.     {
  288.       /* Format a label string */
  289.       sprintf (label_info.label, "%6.2f\nmeters", *valuep);
  290.     }
  291. }
  292.